package houseHold;

import gui.HouseEditor;

import java.util.Vector;

import RoomPanel.RoomPanel;

/**
 * 
 * The house
 * 
 * @author Minodor
 * 
 */
public class House {
	private static House instance = new House();

	public static House getInstance() {
		return instance;
	}

	public static void reset() {
		instance = new House();
		HouseEditor.panels = new Vector<RoomPanel>();
		HouseEditor.getInstance().RoomBuilder.repaint();
	}

	private boolean active = false;

	private Vector<Room> rooms;

	private House() {
		rooms = new Vector<Room>();
		active = false;
		System.gc();
	}

	public void addRoom(Room r) {
		rooms.add(r);
	}

	public Room getRoom(int i) {
		if (i < rooms.size())
			return rooms.get(i);
		return null;
	}

	public Room getRoom(String name) {
		for (int i = 0; i < rooms.size(); i++) {
			if (rooms.get(i).getName().equalsIgnoreCase(name))
				return rooms.get(i);
		}
		return null;
	}

	public Room getRoomByID(int id) {
		for (int i = 0; i < rooms.size(); i++)
			if (rooms.get(i).getID() == id)
				return rooms.get(i);
		return null;
	}

	public int getRoomCount() {
		return rooms.size();
	}

	public Vector<String> getRoomNames() {
		Vector<String> res = new Vector<String>();
		for (int i = 0; i < rooms.size(); i++)
			res.add(rooms.get(i).getName());
		return res;
	}

	public boolean isActive() {
		return this.active;
	}

	public void removeRoom(int id) {
		for (int i = 0; i < rooms.size(); i++)
			if (rooms.get(i).getID() == id)
				rooms.remove(i);

	}

	public void setActive(boolean val) {
		this.active = val;
	}

	@Override
	public String toString() {
		String house = "House:\n";
		for (int i = 0; i < rooms.size(); i++)
			house = house.concat(rooms.get(i).toString());
		return house;
	}

}
